package com.ruoyi.web.controller.tea;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.tea.domain.TeaOrder;
import com.ruoyi.tea.service.ITeaOrderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 订单信息Controller
 * 
 * @author hmx
 * @date 2023-03-18
 */
@RestController
@RequestMapping("/tea/order")
public class TeaOrderController extends BaseController
{
    @Autowired
    private ITeaOrderService teaOrderService;

    /**
     * 查询订单信息列表
     */
    @PreAuthorize("@ss.hasPermi('tea:order:list')")
    @GetMapping("/list")
    public TableDataInfo list(TeaOrder teaOrder)
    {
        startPage();
        List<TeaOrder> list = teaOrderService.selectTeaOrderList(teaOrder);
        return getDataTable(list);
    }

    /**
     * 导出订单信息列表
     */
    @PreAuthorize("@ss.hasPermi('tea:order:export')")
    @Log(title = "订单信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TeaOrder teaOrder)
    {
        List<TeaOrder> list = teaOrderService.selectTeaOrderList(teaOrder);
        ExcelUtil<TeaOrder> util = new ExcelUtil<TeaOrder>(TeaOrder.class);
        util.exportExcel(response, list, "订单信息数据");
    }

    /**
     * 查询订单销量信息echarts列表
     */
    @PreAuthorize("@ss.hasPermi('tea:order:list')")
    @GetMapping("/list/buy")
    public List<TeaOrder> buylist(TeaOrder teaOrder)
    {
        List<TeaOrder> list =teaOrderService.selectBuyOrderList(teaOrder);

        System.out.println("前端传来的参数"+teaOrder);
        return list;
    }
    /**
     * 获取订单信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('tea:order:query')")
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") Long orderId)
    {
        return success(teaOrderService.selectTeaOrderByOrderId(orderId));
    }

    /**
     * 新增订单信息
     */
    @PreAuthorize("@ss.hasPermi('tea:order:add')")
    @Log(title = "订单信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TeaOrder teaOrder)
    {
        return toAjax(teaOrderService.insertTeaOrder(teaOrder));
    }

    /**
     * 修改订单信息
     */
    @PreAuthorize("@ss.hasPermi('tea:order:edit')")
    @Log(title = "订单信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TeaOrder teaOrder)
    {
        return toAjax(teaOrderService.updateTeaOrder(teaOrder));
    }

    /**
     * 删除订单信息
     */
    @PreAuthorize("@ss.hasPermi('tea:order:remove')")
    @Log(title = "订单信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable Long[] orderIds)
    {
        return toAjax(teaOrderService.deleteTeaOrderByOrderIds(orderIds));
    }
}
